//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "FuturesRateHelper.h"
using namespace Cephei::QL::Termstructures::Yield;
#include <gen/QL/Indexes/IborIndex.h>
#include <gen/QL/Quote.h>
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/Termstructures/Yield/RateHelper.h>
using namespace Cephei::QL::Indexes;
using namespace Cephei::QL;
using namespace Cephei::QL::Times;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Termstructures::Yield::CFuturesRateHelper::CFuturesRateHelper (Double price, DateTime immDate, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Double>^ convexityAdjustment) : CRateHelper(CFuturesRateHelper::typeid)
{
    CIborIndex^ _CiborIndex;
    try
    {
#ifdef HANDLE
        _phFuturesRateHelper = NULL;
#endif
        QuantLib::Real _price = (QuantLib::Real)ValueHelper::Convert (price); //d
        QuantLib::Date _immDate = (QuantLib::Date)ValueHelper::Convert (immDate); //d
        _CiborIndex = safe_cast<CIborIndex^> (iborIndex);
        _CiborIndex->Lock();
        boost::shared_ptr<QuantLib::IborIndex>& _iborIndex = static_cast<boost::shared_ptr<QuantLib::IborIndex>&> (_CiborIndex->GetShared ()); 
        QuantLib::Rate _convexityAdjustment = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (convexityAdjustment) ? (QuantLib::Rate)ValueHelper::Convert (convexityAdjustment->Value) : 0.0); //4
        _ppFuturesRateHelper = new boost::shared_ptr<QuantLib::FuturesRateHelper> (new QuantLib::FuturesRateHelper ( _price,  _immDate,  _iborIndex,  _convexityAdjustment ));
        SetRateHelper (boost::dynamic_pointer_cast<QuantLib::RateHelper> (*_ppFuturesRateHelper));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_CiborIndex != nullptr) _CiborIndex->Unlock();
    }
}
Cephei::QL::Termstructures::Yield::CFuturesRateHelper::CFuturesRateHelper (Cephei::QL::IQuote^ price, DateTime immDate, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>^ convexityAdjustment) : CRateHelper(CFuturesRateHelper::typeid)
{
    CQuote^ _Cprice;
    CIborIndex^ _CiborIndex;
    CQuote^ _CconvexityAdjustment;
    try
    {
#ifdef HANDLE
        _phFuturesRateHelper = NULL;
#endif
        _Cprice = safe_cast<CQuote^> (price);
        _Cprice->Lock();
        Handle<QuantLib::Quote>& _price = static_cast<Handle<QuantLib::Quote>&> (_Cprice->GetHandle ()); 
        QuantLib::Date _immDate = (QuantLib::Date)ValueHelper::Convert (immDate); //d
        _CiborIndex = safe_cast<CIborIndex^> (iborIndex);
        _CiborIndex->Lock();
        boost::shared_ptr<QuantLib::IborIndex>& _iborIndex = static_cast<boost::shared_ptr<QuantLib::IborIndex>&> (_CiborIndex->GetShared ()); 
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>::IsSome::get (convexityAdjustment))
        {
            _CconvexityAdjustment = safe_cast<CQuote^> (convexityAdjustment->Value);
            _CconvexityAdjustment->Lock();
        }
        Handle<QuantLib::Quote>& _convexityAdjustment = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>::IsSome::get (convexityAdjustment) ? static_cast<Handle<QuantLib::Quote>&> (_CconvexityAdjustment->GetHandle ()) : Handle<QuantLib::Quote>()); //1
        _ppFuturesRateHelper = new boost::shared_ptr<QuantLib::FuturesRateHelper> (new QuantLib::FuturesRateHelper ( _price,  _immDate,  _iborIndex,  _convexityAdjustment ));
        SetRateHelper (boost::dynamic_pointer_cast<QuantLib::RateHelper> (*_ppFuturesRateHelper));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cprice != nullptr) _Cprice->Unlock();
        if (_CiborIndex != nullptr) _CiborIndex->Unlock();
        if (_CconvexityAdjustment != nullptr) _CconvexityAdjustment->Unlock();
    }
}
Cephei::QL::Termstructures::Yield::CFuturesRateHelper::CFuturesRateHelper (Double price, DateTime immDate, UInt32 lengthInMonths, Cephei::QL::Times::ICalendar^ calendar, QL::Times::BusinessDayConventionEnum convention, Boolean endOfMonth, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<Double>^ convexityAdjustment) : CRateHelper(CFuturesRateHelper::typeid)
{
    CCalendar^ _Ccalendar;
    CDayCounter^ _CdayCounter;
    try
    {
#ifdef HANDLE
        _phFuturesRateHelper = NULL;
#endif
        QuantLib::Real _price = (QuantLib::Real)ValueHelper::Convert (price); //d
        QuantLib::Date _immDate = (QuantLib::Date)ValueHelper::Convert (immDate); //d
        QuantLib::Natural _lengthInMonths = (QuantLib::Natural)ValueHelper::Convert (lengthInMonths); //d
        _Ccalendar = safe_cast<CCalendar^> (calendar);
        _Ccalendar->Lock();
        QuantLib::Calendar& _calendar = static_cast<QuantLib::Calendar&> (_Ccalendar->GetReference ()); 
        QuantLib::BusinessDayConvention _convention = (QuantLib::BusinessDayConvention)convention ;
        bool _endOfMonth = (bool)ValueHelper::Convert (endOfMonth); //d
        _CdayCounter = safe_cast<CDayCounter^> (dayCounter);
        _CdayCounter->Lock();
        QuantLib::DayCounter& _dayCounter = static_cast<QuantLib::DayCounter&> (_CdayCounter->GetReference ()); 
        QuantLib::Rate _convexityAdjustment = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (convexityAdjustment) ? (QuantLib::Rate)ValueHelper::Convert (convexityAdjustment->Value) : 0.0); //4
        _ppFuturesRateHelper = new boost::shared_ptr<QuantLib::FuturesRateHelper> (new QuantLib::FuturesRateHelper ( _price,  _immDate,  _lengthInMonths,  _calendar,  _convention,  _endOfMonth,  _dayCounter,  _convexityAdjustment ));
        SetRateHelper (boost::dynamic_pointer_cast<QuantLib::RateHelper> (*_ppFuturesRateHelper));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Ccalendar != nullptr) _Ccalendar->Unlock();
        if (_CdayCounter != nullptr) _CdayCounter->Unlock();
    }
}
Cephei::QL::Termstructures::Yield::CFuturesRateHelper::CFuturesRateHelper (Cephei::QL::IQuote^ price, DateTime immDate, UInt32 lengthInMonths, Cephei::QL::Times::ICalendar^ calendar, QL::Times::BusinessDayConventionEnum convention, Boolean endOfMonth, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>^ convexityAdjustment) : CRateHelper(CFuturesRateHelper::typeid)
{
    CQuote^ _Cprice;
    CCalendar^ _Ccalendar;
    CDayCounter^ _CdayCounter;
    CQuote^ _CconvexityAdjustment;
    try
    {
#ifdef HANDLE
        _phFuturesRateHelper = NULL;
#endif
        _Cprice = safe_cast<CQuote^> (price);
        _Cprice->Lock();
        Handle<QuantLib::Quote>& _price = static_cast<Handle<QuantLib::Quote>&> (_Cprice->GetHandle ()); 
        QuantLib::Date _immDate = (QuantLib::Date)ValueHelper::Convert (immDate); //d
        QuantLib::Natural _lengthInMonths = (QuantLib::Natural)ValueHelper::Convert (lengthInMonths); //d
        _Ccalendar = safe_cast<CCalendar^> (calendar);
        _Ccalendar->Lock();
        QuantLib::Calendar& _calendar = static_cast<QuantLib::Calendar&> (_Ccalendar->GetReference ()); 
        QuantLib::BusinessDayConvention _convention = (QuantLib::BusinessDayConvention)convention ;
        bool _endOfMonth = (bool)ValueHelper::Convert (endOfMonth); //d
        _CdayCounter = safe_cast<CDayCounter^> (dayCounter);
        _CdayCounter->Lock();
        QuantLib::DayCounter& _dayCounter = static_cast<QuantLib::DayCounter&> (_CdayCounter->GetReference ()); 
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>::IsSome::get (convexityAdjustment))
        {
            _CconvexityAdjustment = safe_cast<CQuote^> (convexityAdjustment->Value);
            _CconvexityAdjustment->Lock();
        }
        Handle<QuantLib::Quote>& _convexityAdjustment = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>::IsSome::get (convexityAdjustment) ? static_cast<Handle<QuantLib::Quote>&> (_CconvexityAdjustment->GetHandle ()) : Handle<QuantLib::Quote>()); //1
        _ppFuturesRateHelper = new boost::shared_ptr<QuantLib::FuturesRateHelper> (new QuantLib::FuturesRateHelper ( _price,  _immDate,  _lengthInMonths,  _calendar,  _convention,  _endOfMonth,  _dayCounter,  _convexityAdjustment ));
        SetRateHelper (boost::dynamic_pointer_cast<QuantLib::RateHelper> (*_ppFuturesRateHelper));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cprice != nullptr) _Cprice->Unlock();
        if (_Ccalendar != nullptr) _Ccalendar->Unlock();
        if (_CdayCounter != nullptr) _CdayCounter->Unlock();
        if (_CconvexityAdjustment != nullptr) _CconvexityAdjustment->Unlock();
    }
}
Cephei::QL::Termstructures::Yield::CFuturesRateHelper::CFuturesRateHelper (Double price, DateTime immStartDate, DateTime endDate, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<Double>^ convexityAdjustment) : CRateHelper(CFuturesRateHelper::typeid)
{
    CDayCounter^ _CdayCounter;
    try
    {
#ifdef HANDLE
        _phFuturesRateHelper = NULL;
#endif
        QuantLib::Real _price = (QuantLib::Real)ValueHelper::Convert (price); //d
        QuantLib::Date _immStartDate = (QuantLib::Date)ValueHelper::Convert (immStartDate); //d
        QuantLib::Date _endDate = (QuantLib::Date)ValueHelper::Convert (endDate); //d
        _CdayCounter = safe_cast<CDayCounter^> (dayCounter);
        _CdayCounter->Lock();
        QuantLib::DayCounter& _dayCounter = static_cast<QuantLib::DayCounter&> (_CdayCounter->GetReference ()); 
        QuantLib::Rate _convexityAdjustment = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (convexityAdjustment) ? (QuantLib::Rate)ValueHelper::Convert (convexityAdjustment->Value) : 0.0); //4
        _ppFuturesRateHelper = new boost::shared_ptr<QuantLib::FuturesRateHelper> (new QuantLib::FuturesRateHelper ( _price,  _immStartDate,  _endDate,  _dayCounter,  _convexityAdjustment ));
        SetRateHelper (boost::dynamic_pointer_cast<QuantLib::RateHelper> (*_ppFuturesRateHelper));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_CdayCounter != nullptr) _CdayCounter->Unlock();
    }
}
Cephei::QL::Termstructures::Yield::CFuturesRateHelper::CFuturesRateHelper (Cephei::QL::IQuote^ price, DateTime immStartDate, DateTime endDate, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>^ convexityAdjustment) : CRateHelper(CFuturesRateHelper::typeid)
{
    CQuote^ _Cprice;
    CDayCounter^ _CdayCounter;
    CQuote^ _CconvexityAdjustment;
    try
    {
#ifdef HANDLE
        _phFuturesRateHelper = NULL;
#endif
        _Cprice = safe_cast<CQuote^> (price);
        _Cprice->Lock();
        Handle<QuantLib::Quote>& _price = static_cast<Handle<QuantLib::Quote>&> (_Cprice->GetHandle ()); 
        QuantLib::Date _immStartDate = (QuantLib::Date)ValueHelper::Convert (immStartDate); //d
        QuantLib::Date _endDate = (QuantLib::Date)ValueHelper::Convert (endDate); //d
        _CdayCounter = safe_cast<CDayCounter^> (dayCounter);
        _CdayCounter->Lock();
        QuantLib::DayCounter& _dayCounter = static_cast<QuantLib::DayCounter&> (_CdayCounter->GetReference ()); 
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>::IsSome::get (convexityAdjustment))
        {
            _CconvexityAdjustment = safe_cast<CQuote^> (convexityAdjustment->Value);
            _CconvexityAdjustment->Lock();
        }
        Handle<QuantLib::Quote>& _convexityAdjustment = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>::IsSome::get (convexityAdjustment) ? static_cast<Handle<QuantLib::Quote>&> (_CconvexityAdjustment->GetHandle ()) : Handle<QuantLib::Quote>()); //1
        _ppFuturesRateHelper = new boost::shared_ptr<QuantLib::FuturesRateHelper> (new QuantLib::FuturesRateHelper ( _price,  _immStartDate,  _endDate,  _dayCounter,  _convexityAdjustment ));
        SetRateHelper (boost::dynamic_pointer_cast<QuantLib::RateHelper> (*_ppFuturesRateHelper));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cprice != nullptr) _Cprice->Unlock();
        if (_CdayCounter != nullptr) _CdayCounter->Unlock();
        if (_CconvexityAdjustment != nullptr) _CconvexityAdjustment->Unlock();
    }
}
Cephei::QL::Termstructures::Yield::CFuturesRateHelper::CFuturesRateHelper (boost::shared_ptr<QuantLib::FuturesRateHelper>& childNative, Object^ owner) : CRateHelper(CFuturesRateHelper::typeid)
{
#ifdef HANDLE
	_phFuturesRateHelper = NULL;
#endif
	_ppFuturesRateHelper = &childNative;
    _ppRateHelper = new boost::shared_ptr<QuantLib::RateHelper> (boost::dynamic_pointer_cast<QuantLib::RateHelper> (*_ppFuturesRateHelper));
}
Cephei::QL::Termstructures::Yield::CFuturesRateHelper::CFuturesRateHelper (QuantLib::FuturesRateHelper& childNative, Object^ owner) : CRateHelper(CFuturesRateHelper::typeid)
{
#ifdef HANDLE
	_phFuturesRateHelper = NULL;
#endif
	_ppFuturesRateHelper = new boost::shared_ptr<QuantLib::FuturesRateHelper> (&childNative);
    _ppRateHelper = new boost::shared_ptr<QuantLib::RateHelper> (boost::dynamic_pointer_cast<QuantLib::RateHelper> (*_ppFuturesRateHelper));
    _FuturesRateHelperOwner = owner;
    _RateHelperOwner = owner;
}

Cephei::QL::Termstructures::Yield::CFuturesRateHelper::CFuturesRateHelper (CFuturesRateHelper^ copy) : CRateHelper(CFuturesRateHelper::typeid)
{
#ifdef HANDLE
	_phFuturesRateHelper = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppFuturesRateHelper = new boost::shared_ptr<QuantLib::FuturesRateHelper> (copy->GetShared());
        _ppRateHelper = new boost::shared_ptr<QuantLib::RateHelper> (boost::dynamic_pointer_cast<QuantLib::RateHelper> (*_ppFuturesRateHelper));
    }
}
Cephei::QL::Termstructures::Yield::CFuturesRateHelper::CFuturesRateHelper (PLATFORM::Type^ t) : CRateHelper(CFuturesRateHelper::typeid)
{
#ifdef HANDLE
	_phFuturesRateHelper = NULL;
#endif
	if (!t->IsSubclassOf(CFuturesRateHelper::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Termstructures::Yield::CFuturesRateHelper::CFuturesRateHelper (QuantLib::Handle<QuantLib::FuturesRateHelper>& childNative, Object^ owner)  : CRateHelper(CFuturesRateHelper::typeid)
{
	_phFuturesRateHelper = &childNative;
	_ppFuturesRateHelper = &static_cast<boost::shared_ptr<QuantLib::FuturesRateHelper>>(childNative.currentLink());
    _ppRateHelper = new boost::shared_ptr<QuantLib::RateHelper> (boost::dynamic_pointer_cast<QuantLib::RateHelper> (*_ppFuturesRateHelper));
    _FuturesRateHelperOwner = owner;
}
Cephei::QL::Termstructures::Yield::CFuturesRateHelper::CFuturesRateHelper (QuantLib::Handle<QuantLib::FuturesRateHelper> childNative)  : CRateHelper(CFuturesRateHelper::typeid)
{
	_phFuturesRateHelper = &childNative;
	_ppFuturesRateHelper = &static_cast<boost::shared_ptr<QuantLib::FuturesRateHelper>>(childNative.currentLink());
    _ppRateHelper = new boost::shared_ptr<QuantLib::RateHelper> (boost::dynamic_pointer_cast<QuantLib::RateHelper> (*_ppFuturesRateHelper));
}
#endif
#ifdef STRUCT
Cephei::QL::Termstructures::Yield::CFuturesRateHelper::CFuturesRateHelper (QuantLib::FuturesRateHelper childNative)  : CRateHelper(CFuturesRateHelper::typeid)
{
#ifdef HANDLE
	_phFuturesRateHelper = NULL;
#endif
	_ppFuturesRateHelper = new boost::shared_ptr<QuantLib::FuturesRateHelper> (new QuantLib::FuturesRateHelper (childNative));
    _ppRateHelper = new boost::shared_ptr<QuantLib::RateHelper> (boost::dynamic_pointer_cast<QuantLib::RateHelper> (*_ppFuturesRateHelper));
}
#endif

Cephei::QL::Termstructures::Yield::CFuturesRateHelper::~CFuturesRateHelper ()
{
    if (_ppFuturesRateHelper != NULL)
    {
	    delete _ppFuturesRateHelper;
        _ppFuturesRateHelper = NULL;
    }
}
Cephei::QL::Termstructures::Yield::CFuturesRateHelper::!CFuturesRateHelper ()
{
    if (_ppFuturesRateHelper != NULL)
    {
	    delete _ppFuturesRateHelper;
    }
}
QuantLib::FuturesRateHelper& Cephei::QL::Termstructures::Yield::CFuturesRateHelper::GetReference ()
{
    if (_ppFuturesRateHelper == NULL) throw REFNEW NativeNullException ();
	return **_ppFuturesRateHelper;
}
boost::shared_ptr<QuantLib::FuturesRateHelper>& Cephei::QL::Termstructures::Yield::CFuturesRateHelper::GetShared ()
{
    if (_ppFuturesRateHelper == NULL) throw REFNEW NativeNullException ();
	return *_ppFuturesRateHelper;
}
QuantLib::FuturesRateHelper* Cephei::QL::Termstructures::Yield::CFuturesRateHelper::GetPointer ()
{
    if (_ppFuturesRateHelper == NULL) throw REFNEW NativeNullException ();
	return &**_ppFuturesRateHelper;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::FuturesRateHelper>& Cephei::QL::Termstructures::Yield::CFuturesRateHelper::GetHandle ()
{
	if (_phFuturesRateHelper == NULL)
	{
		_phFuturesRateHelper = new Handle<QuantLib::FuturesRateHelper> (*_ppFuturesRateHelper);
	}
	return *_phFuturesRateHelper;
}
#endif
bool Cephei::QL::Termstructures::Yield::CFuturesRateHelper::HasNative () 
{
	return (_ppFuturesRateHelper != NULL);
}

Double Cephei::QL::Termstructures::Yield::CFuturesRateHelper::ConvexityAdjustment::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppFuturesRateHelper)->convexityAdjustment ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::Yield::CFuturesRateHelper::ImpliedQuote::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppFuturesRateHelper)->impliedQuote ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Termstructures::Yield::IFuturesRateHelper^ Cephei::QL::Termstructures::Yield::CFuturesRateHelper_Factory::Create (Double price, DateTime immDate, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Double>^ convexityAdjustment)
{
    return REFNEW CFuturesRateHelper ( price,  immDate,  iborIndex,  convexityAdjustment);
}
Cephei::QL::Termstructures::Yield::IFuturesRateHelper^ Cephei::QL::Termstructures::Yield::CFuturesRateHelper_Factory::Create (Cephei::QL::IQuote^ price, DateTime immDate, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>^ convexityAdjustment)
{
    return REFNEW CFuturesRateHelper ( price,  immDate,  iborIndex,  convexityAdjustment);
}
Cephei::QL::Termstructures::Yield::IFuturesRateHelper^ Cephei::QL::Termstructures::Yield::CFuturesRateHelper_Factory::Create (Double price, DateTime immDate, UInt32 lengthInMonths, Cephei::QL::Times::ICalendar^ calendar, QL::Times::BusinessDayConventionEnum convention, Boolean endOfMonth, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<Double>^ convexityAdjustment)
{
    return REFNEW CFuturesRateHelper ( price,  immDate,  lengthInMonths,  calendar,  convention,  endOfMonth,  dayCounter,  convexityAdjustment);
}
Cephei::QL::Termstructures::Yield::IFuturesRateHelper^ Cephei::QL::Termstructures::Yield::CFuturesRateHelper_Factory::Create (Cephei::QL::IQuote^ price, DateTime immDate, UInt32 lengthInMonths, Cephei::QL::Times::ICalendar^ calendar, QL::Times::BusinessDayConventionEnum convention, Boolean endOfMonth, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>^ convexityAdjustment)
{
    return REFNEW CFuturesRateHelper ( price,  immDate,  lengthInMonths,  calendar,  convention,  endOfMonth,  dayCounter,  convexityAdjustment);
}
Cephei::QL::Termstructures::Yield::IFuturesRateHelper^ Cephei::QL::Termstructures::Yield::CFuturesRateHelper_Factory::Create (Double price, DateTime immStartDate, DateTime endDate, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<Double>^ convexityAdjustment)
{
    return REFNEW CFuturesRateHelper ( price,  immStartDate,  endDate,  dayCounter,  convexityAdjustment);
}
Cephei::QL::Termstructures::Yield::IFuturesRateHelper^ Cephei::QL::Termstructures::Yield::CFuturesRateHelper_Factory::Create (Cephei::QL::IQuote^ price, DateTime immStartDate, DateTime endDate, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>^ convexityAdjustment)
{
    return REFNEW CFuturesRateHelper ( price,  immStartDate,  endDate,  dayCounter,  convexityAdjustment);
}
